<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    table,
    th,
    td {
      border: 1px solid black;
    }
  </style>
</head>

<body>
  <?php
  // $xmm = trim($xm);
  $xmm = $_GET["xm"];
  $xmm = trim($xmm);
  if ($xmm === "") {
    echo '请输入员工的姓名';
    die();
  }
  $xm0 = "%" . $xmm . "%";
  $link = mysqli_connect("localhost", "root", "2580") or die("服务器连接失败!<br>");
  mysqli_select_db($link, "new") or die("服务器选择失败!<br>"); //new数据库
  $sql = "select * from info where name like '$x0' "; //info表
  $result = mysqli_query($link, $sql);
  $rows = mysqli_num_rows($result); //总记录数
  if ($rows == 0) {
    echo "没有满足条件的记录";
    // die();
  } else {
    $pagesize = 2; //设置每一页的记录数是2
    $pagecount = ceil($rows / $pagesize);
    if (!isset($pageno) || ($pageno < 1)) {
      $pageno = 1;
    }
    if ($pageno > $pagecount) {
      $pageno = $pagecount;
    }
    $offset = ($pageno - 1) * $pagesize;
    mysqli_data_seek($result, $offset);
  }

  ?>
  <div>
    <strong>查询结果</strong>
  </div>
  <table>
    <tr>
      <td>
        <div> 员工序号:</div>
      </td>
      <td>
        <div> 姓名:</div>
      </td>
      <td>
        <div> 年龄:</div>
      </td>
    </tr>
    <?php
    $i = 0;
    while ($row = mysqli_fetch_array($result)) {
    ?>
      <tr>
        <td>
          <div>1</div>
        </td>
        <td>
          <div><?php echo $row['name'] ?></div>
        </td>
        <td>
          <div><?php echo $row['age'] ?></div>
        </td>
      </tr>
    <?php
      $i = $i + 1;
      if ($i == $pagesize)
        break;
    }
    mysqli_free_result($result);
    mysqli_close($link);
    ?>
  </table>
  <div>
    [第<?php echo $pageno; ?>页]/共[<?php echo $pagecount; ?>页]
    <?php
    $href = $PHP_SELF . "?xm=" . urlencode($xm);
    if ($pageno <> 1) {
    ?>
      <a href="<?php echo $href; ?>&pageno=1">首页</a>
      <a href="<?php echo $href; ?>&pageno=<?php echo $pageno - 1; ?>">上一页</a>
    <?php
    }
    if ($pageno <> $pagecount) { ?>

      <a href="<?php echo $href; ?>&pageno=<?php echo $pageno + 1; ?>">下一页</a>
    <?php
    }
    ?>
    [共找到<?php echo $rows; ?>个记录]
  </div>
</body>

</html>